//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using OpenLS.Spreadsheet.UI.Resources;

namespace OpenLS.Spreadsheet.UI
{
    public class CellStyleGrouping : GroupDescription
    {
        public CellStyleGrouping()
        {
            foreach (string str in GetResources())
            {
                string first = str.Split('|')[0];
                GroupNames.Add(first);
            }
            return;
        }

        private static IEnumerable<string> GetResources()
        {
            foreach (string str in new List<string>
            {
                CellGroupResources.GoodBadNeutral,
                CellGroupResources.DataAndModel,
                CellGroupResources.TitlesHeadings,
                CellGroupResources.ThemedCellStyle,
                CellGroupResources.NumberFormat
            }
        )
            yield return str;
        }

        public override object GroupNameFromItem(object item, int level, CultureInfo culture)
        {
            var style = item as CellStyle;
            if (style == null)
                return "<NONE>";
            foreach (string str in GetResources())
            {
                foreach (string s2 in str.Split('|'))
                    if (s2 == style.Name)
                        return str.Split('|')[0];
            }
            return CellGroupResources.Other;


        }
    }
}